#region Usings
using System.Web;

using BK.BlusinessLogic;
using BK.Model;
using BK.Repositories.Abstract;
using BK.Repositories.Factory;

using Lib.ApplicationBlocks.DbBlocks.Membership;
#endregion

namespace BK.UI.Web.AppCode
{
    public class UserProvider : GeneralMembershipProvider
    {
    	private static UserProvider _instance;
    	private static readonly object _lockObj = new object();
    	private static readonly object _lockObj2 = new object();

        #region Instance Methods
        protected override IMembership CreateInstanceOfMembership(string login, string password)
        {
            return new User {Email = login, Password = password};
        }
        #endregion

        #region Instance Properties
        protected override IMgrMemberships MgrMemberships
        {
            get { return RepositoryFactory.Get<IUsersRepository>(); }
        }
        #endregion

        #region Class Methods
        public static User GetCurrentUser()
        {
            User result = new UsersBl().GetByEmail(HttpContext.Current.User.Identity.Name);
            return result;
        }
        #endregion

    	public static UserProvider Instance
    	{
    		get
    		{
    			lock (_lockObj)
    			{
					if (_instance == null)
					{
						lock (_lockObj2)
						{
							_instance = new UserProvider();
						}
					}
    			}
				return _instance;
    		}
    	}
    }
}